// 主页面上的倒计时显示
function CountDown(){}
$.extend(CountDown.prototype,{
    init :function(){
        this.timestart =$(".time_star"); 
        this.hours   =$(".hours");
        this.minutes =$(".minutes");
        this.seconds =$(".seconds");
        this.flag    = true;
        this.now_time  = new Date();//获取现在时间
        this.countDown() // 倒计时目标事件的计算 和调用倒计时
    },
    countDown : function(){
        var start = this.now_time.getHours()
        this.timestart.html(`${start}:00场`);
        //设置目标时间
        var target_time = this.now_time.setHours(start+1);
            target_time = this.now_time.setMinutes(0);
            target_time = this.now_time.setSeconds(0);
            target_time = this.now_time.setMilliseconds(0);
        var timer = setInterval($.proxy(function(){
            this.daojishi(target_time);
            if(!this.flag){
                clearInterval(timer);
                this.init();
            }
        },this),1000)
    },
    daojishi : function(target){
        var n_time = new Date();
        var diff = target - n_time;
        var hour=Math.floor(diff/1000/60/60).toString().padStart(2, "0"),
            minutes=Math.floor((diff-hour*1000*60*60)/1000/60).toString().padStart(2, "0"),
            seconds=Math.floor((diff-hour*1000*60*60-minutes*1000*60)/1000).toString().padStart(2, "0");
        this.hours.html(hour);
        this.minutes.html(minutes);
        this.seconds.html(seconds);
        if(diff <= 0){
            this.flag = false;
            this.hours.html("00");
            this.minutes.html("00");
            this.seconds.html("00");
        }
    }
})
export default new CountDown();